package handler

import (
	"road-smart/models"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

func Add(c *gin.Context) {
	road_name := c.PostForm("road_name")
	road_seat := c.PostForm("road_seat")
	if road_name == "" || road_seat == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不可为空",
		})
		return
	}
	data := models.Road{
		Model:    gorm.Model{},
		RoadName: road_name,
		RoadSeat: road_seat,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
